-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoint to transcribe videos #554
base: master
Are you sure you want to change the base?
Conversation
ekrojo77
commented
Dec 5, 2024
•
edited
Loading
edited
- Testing
- Endepunkt for å polle om filen er opprettet
- Bedre return fra GET
case Success(_) => Right(()) | ||
case Failure(ex) => returnLeftError(ex) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beholder disse i første omgang før vi vet hva som trengs av endepunkt. Men tror det rene transcribe-endepunktet er det som vil bli mest brukt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lisenspirk
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/model/api/TranscriptionResultDTO.scala
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/service/TranscriptionService.scala
Show resolved
Hide resolved
audio-api/src/test/scala/no/ndla/audioapi/service/TranscriptionServiceTest.scala
Show resolved
Hide resolved
common/src/main/scala/no/ndla/common/brightcove/NdlaBrightcoveClient.scala
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
common/src/main/scala/no/ndla/common/brightcove/NdlaBrightcoveClient.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/AudioApiProperties.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/AudioApiProperties.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/controller/TranscriptionController.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/service/TranscriptionService.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/service/TranscriptionService.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/service/TranscriptionService.scala
Outdated
Show resolved
Hide resolved
audio-api/src/main/scala/no/ndla/audioapi/service/TranscriptionService.scala
Outdated
Show resolved
Hide resolved
common/src/main/scala/no/ndla/common/brightcove/NdlaBrightcoveClient.scala
Outdated
Show resolved
Hide resolved
common/src/main/scala/no/ndla/common/brightcove/NdlaBrightcoveClient.scala
Outdated
Show resolved
Hide resolved
def getVideoTranscription( | ||
videoId: String, | ||
language: String | ||
): Try[Either[String, String]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeg synes fortsatt det er vanskelig å vite hva denne typen representerer uten å dykke ned i hva funksjonen gjør og returnerer.
Kanskje vi kunne brukt en trait som enten kunne være success eller ikke?
Noe sånt?
sealed trait TranscriptionResult
case class TranscriptionComplete(transcription: String) extends TranscriptionResult
case class TranscriptionNonComplete(transcriptionStatus: String) extends TranscriptionResult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Da kan vi gjøre feks sånn:
getObjectFromS3(transcribeUri).map(TranscriptionComplete)
} else {
Success(TranscriptionNonComplete(transcriptionJobStatus))
|
||
transcribeClient.getTranscriptionJob(jobName).flatMap { transcriptionJobResponse => | ||
val transcriptionJob = transcriptionJobResponse.transcriptionJob() | ||
val transcriptionJobStatus = transcriptionJob.transcriptionJobStatus().toString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Denne trenger vel egentlig ikke konverteres til en streng?
val authResponse = request.send(backend) | ||
Try { | ||
authResponse.body match { | ||
case Right(jsonString) => | ||
decode[TokenResponse](jsonString) match { | ||
case Right(tokenResponse) => tokenResponse.access_token | ||
case Left(error) => throw new Exception(s"Failed to decode token response: ${error.getMessage}") | ||
} | ||
case Left(error) => throw new Exception(s"Failed to get token: ${error}") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request.send(backend)
kan potensielt kaste exception så den burde nok være med i Try
'en, kanskje noe sånt?
val authResponse = request.send(backend) | |
Try { | |
authResponse.body match { | |
case Right(jsonString) => | |
decode[TokenResponse](jsonString) match { | |
case Right(tokenResponse) => tokenResponse.access_token | |
case Left(error) => throw new Exception(s"Failed to decode token response: ${error.getMessage}") | |
} | |
case Left(error) => throw new Exception(s"Failed to get token: ${error}") | |
} | |
Try(request.send(backend).body) match { | |
case Success(Right(jsonString)) => | |
decode[TokenResponse](jsonString) match { | |
case Right(tokenResponse) => Success(tokenResponse.access_token) | |
case Left(error) => Failure(new Exception(s"Failed to decode token response: ${error.getMessage}")) | |
} | |
case Success(Left(error)) => Failure(new Exception(s"Failed to get token: ${error}")) | |
case Failure(ex) => Failure(ex) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideelt sett så burde vi sikkert lage noen spesifikke Exception
typer og (eller gjenbruke om vi har noen som finnes allerede)
val response = request.send(backend) | ||
Try { | ||
response.body match { | ||
case Right(jsonString) => | ||
parse(jsonString) match { | ||
case Right(json) => | ||
json.asArray match { | ||
case Some(videoSources) => videoSources | ||
case None => throw new Exception("Failed to parse video source") | ||
} | ||
case Left(error) => throw new Exception(s"Failed to parse video source: ${error.getMessage}") | ||
} | ||
case Left(error) => throw new Exception(s"Failed to get video source: ${error}") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Samme her:
val response = request.send(backend) | |
Try { | |
response.body match { | |
case Right(jsonString) => | |
parse(jsonString) match { | |
case Right(json) => | |
json.asArray match { | |
case Some(videoSources) => videoSources | |
case None => throw new Exception("Failed to parse video source") | |
} | |
case Left(error) => throw new Exception(s"Failed to parse video source: ${error.getMessage}") | |
} | |
case Left(error) => throw new Exception(s"Failed to get video source: ${error}") | |
} | |
} | |
Try(request.send(backend).body) match { | |
case Success(Right(jsonString)) => | |
parse(jsonString) match { | |
case Right(json) => | |
json.asArray match { | |
case Some(videoSources) => Success(videoSources) | |
case None => Failure(new Exception("Failed to parse video source")) | |
} | |
case Left(error) => Failure(new Exception(s"Failed to parse video source: ${error.getMessage}")) | |
} | |
case Success(Left(error)) => Failure(new Exception(s"Failed to get video source: ${error}")) | |
case Failure(ex) => Failure(ex) | |
} |